package com.junzhiit.nengji.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.bainaeco.framework.enums.IsDelete;
import com.junzhiit.nengji.bo.RechargeConfigureBO;
import com.junzhiit.nengji.dao.RechargeConfigureDAO;
import com.junzhiit.nengji.model.RechargeConfigure;

@Repository
public class RechargeConfigureDAOImpl extends AbstractBaseDAO<RechargeConfigure> implements RechargeConfigureDAO {

	@Override
	public RechargeConfigure getByRechargeMoney(Double rechargeMoney, Integer giveType) {
		StringBuffer sql=new StringBuffer();
		StatementParameter param=new StatementParameter();
		
		sql.append(" select * from recharge_configure where recharge_money = ? and give_type = ? and is_delete = ? ");
		
		param.setDouble(rechargeMoney);
		param.setInt(giveType);
		param.setInt(IsDelete.NO.toIntValue());
		
		return super.query(sql.toString(), RechargeConfigure.class, param);
	}

	@Override
	public List<RechargeConfigure> findAll(RechargeConfigureBO bo, int pageNumber, int maxPageRow) {
		StringBuffer sql=new StringBuffer();
		StatementParameter param=new StatementParameter();
		
		sql.append("  select * from recharge_configure where is_delete = ? ");
		param.setInt(IsDelete.NO.toIntValue());
		
		if(bo.getRechargeMoney()!=null){
			sql.append(" and recharge_money = ? ");
			param.setDouble(bo.getRechargeMoney());
		}
		
		if(bo.getGiveType()!=null){
			sql.append(" and give_type = ? ");
			param.setInt(bo.getGiveType());
		}
		
		if(bo.getGiveValue()!=null){
			sql.append(" and give_value = ? ");
			param.setDouble(bo.getGiveValue());
		}
		
		return super.queryForPagingList(sql.toString(), RechargeConfigure.class, param, pageNumber,maxPageRow);
	}

	@Override
	public int getTotalCount(RechargeConfigureBO bo) {
		StringBuffer sql=new StringBuffer();
		StatementParameter param=new StatementParameter();
		
		sql.append("  select count(*) from recharge_configure where is_delete = ? ");
		param.setInt(IsDelete.NO.toIntValue());
		
		if(bo.getRechargeMoney()!=null){
			sql.append(" and recharge_money = ? ");
			param.setDouble(bo.getRechargeMoney());
		}
		
		if(bo.getGiveType()!=null){
			sql.append(" and give_type = ? ");
			param.setInt(bo.getGiveType());
		}
		
		if(bo.getGiveValue()!=null){
			sql.append(" and give_value = ? ");
			param.setDouble(bo.getGiveValue());
		}
		
		return super.queryForInt(sql.toString(), param);
	}

	@Override
	public RechargeConfigure getRechargeMoney(Double rechargeMoney) {
		StringBuffer sql=new StringBuffer();
		StatementParameter param=new StatementParameter();
		sql.append(" select * from recharge_configure where recharge_money <= ?  order by recharge_money desc limit 1 ");
		param.setDouble(rechargeMoney);
		return super.query(sql.toString(), RechargeConfigure.class, param);
	}

}
